In this tutorial I will show you how to convert csv to pdf using pdfkit python.
CODE:
import pandas as pd import pdfkit df1 = pd.read_csv('shampoo_sales.csv') html_string = df1.to_html() pdfkit.from_string(html_string, "output_file.pdf") print("PDF file saved.")
OSERROR ERROR:
I got this following error while running the program to convert csv to pdf using python.
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
SOLUTION:
Download wkhtmltopdf.exe from https://wkhtmltopdf.org/ and install it. Then specify the path to wkhtmltopdf executable.
config=pdfkit.configuration(wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe')
CODE:
import pandas as pd import pdfkit df1 = pd.read_csv('shampoo_sales.csv') html_string = df1.to_html() config=pdfkit.configuration(wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe') pdfkit.from_string(html_string, "output_file.pdf",configuration=config) print("PDF file saved.")
VIDEO GUIDE:
Post your comments / questions
Recent Article
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
Related Article